import {
  unstable_HistoryRouter as HistoryRouter,
  BrowserRouter,
  Routes,
  Route,
} from 'react-router-dom'
import { lazy, Suspense } from 'react'
import { history } from './utils/history'
import AuthComponent from './components/AuthComponent'
// import Layout from './pages/Layout'
// import Login from './pages/Login'
// import Home from './pages/Home'
// import Article from './pages/Article'
// import Publish from './pages/Publish'
import './App.css'

// 按需导入路由组件
const Login = lazy(() => import('./pages/Login'))
const Layout = lazy(() => import('./pages/Layout'))
const Home = lazy(() => import('./pages/Home'))
const Article = lazy(() => import('./pages/Article'))
const Publish = lazy(() => import('./pages/Publish'))

function App() {
  return (
    // 路由配置

    <HistoryRouter history={history}>
      <div className='App'>
        <Suspense
          fallback={
            <div
              style={{
                textAlign: 'center',
                marginTop: 200,
              }}
            >
              loading...
            </div>
          }
        >
          <Routes>
            <Route
              path='/'
              element={
                <AuthComponent>
                  <Layout />
                </AuthComponent>
              }
            >
              <Route index element={<Home />}></Route>
              <Route path='/article' element={<Article />}></Route>
              <Route path='/publish' element={<Publish />}></Route>
            </Route>
            <Route path='/login' element={<Login />}></Route>
          </Routes>
        </Suspense>
      </div>
    </HistoryRouter>
  )
}

export default App
